package org.baicaixiaozhan.learn.guava.collect;

import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * DESC: {@link ImmutableCollection} 示例
 *
 * @author baicaixiaozhan
 * @since 2020/11/13
 */
public class ImmutableCollections {

    public static void main(String[] args) {

        similarImmutableAsListInJava();

        immutableCollectionsInJava();

        immutableCollectionsInGuava();
    }

    public static void similarImmutableAsListInJava() {
        List<Integer> integers = Arrays.asList(1, 2, 3, 4, 5);
        integers.add(1);
        integers.forEach(System.out::println);
    }

    public static void immutableCollectionsInJava() {
        List<Integer> integers = Collections.unmodifiableList(Lists.newArrayList(1, 2, 3, 4, 5));
        integers.add(1);
        integers.forEach(System.out::println);
    }

    public static void immutableCollectionsInGuava() {
        List<Integer> integers = ImmutableList.of(1, 2, 3, 4, 5);
        integers.add(1);
        integers.forEach(System.out::println);
    }
}
